package game.block.command;

import game.block.Constants;
import game.block.Locator;
import game.block.entity.Entity;
import game.block.entity.MovableEntity;
import game.block.game.Board;
import game.block.tile.Tile;

public class ExplodeCommand extends Command implements Constants{

    private MovableEntity block;
    private Tile tile;
    private Entity tileEntity;
    private Board gameBoard;
    
    public ExplodeCommand(MovableEntity block, Tile tile, Board gameBoard){
        this.block=block;
        this.tile=tile;
        this.gameBoard=gameBoard;
        tileEntity=tile.getEntities().get(0);
    }
    
    @Override
    public void execute() {
        block.explode(tile);
        remove(block);
        remove(tileEntity);
        tile.changeColor(COLOR.BLANK);
        //tile.remove(0);
        Locator.getAudio().playSound(SOUND.EXPLODE.getValue());
    }

    public void remove(Entity entity){
        entity.getCurrentTile().remove(entity);
        gameBoard.getEntities().remove(entity);
    }
    
    public void add(Entity entity){
        entity.getCurrentTile().add(entity);
        gameBoard.getEntities().add(entity);
    }

    @Override
    public void undo() {
        add(block);
        add(tileEntity);
        //tile.add(tileEntity);
        tileEntity.unhideSprite();
    }

}
